package com.yc.vote.controller;

import com.yc.vote.service.BizException;
import com.yc.vote.vo.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Component
@RestControllerAdvice  // 全局攔截
//@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler
    public Result handleBizException(BizException e){
        e.printStackTrace();
        return new Result(0,e.getMessage(), null);
    }

    @ExceptionHandler
    public Result unsupportedOperationException(UnsupportedOperationException e){
        e.printStackTrace();
        return new Result(-1,e.getMessage(), null);
    }

    @ExceptionHandler
    public Result exception(Exception e){
        e.printStackTrace();
        return new Result(-2,e.getMessage(), null);
    }
}
